package com.kantboot.system.user.dao.repository.entity;

import com.kantboot.system.user.domain.dto.SysRoleSearchDTO;
import com.kantboot.system.user.domain.entity.SysRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface SysRoleRepository extends JpaRepository<SysRole, Long> {

    /**
     * 根据用户id获取角色列表
     */
    @Query("""
    SELECT r FROM SysRole r
    WHERE 
    (:#{#param.code} IS NULL OR r.code = :#{#param.code})
    AND (:#{#param.name} IS NULL OR r.name = :#{#param.name})
    ORDER BY r.priority DESC
    """)
    Page<SysRole> getBodyData(@Param("param")SysRoleSearchDTO param, Pageable pageable);


}
